import React,{Component} from 'react'
import {connect} from 'react-redux'
import CommentList from '../component/CommentList'
import {deleteComment} from '../action/action'
class CommentListContainer extends Component{
    handleOnDeleteComment(index){
        if(this.props.onDelete){
            this.props.onDelete(index)
        }
    }
    render(){
        return(
            <CommentList
                comments={this.props.comments}
                onDelete={this.handleOnDeleteComment.bind(this)}/>
        )
    }
}
const mapStateToProps = (state) => {
  return {
    comments: state.comments
  }
}
const mapDispatchToProps = (dispatch)=>{
    return {
        onDelete:(index)=>{
            dispatch(deleteComment(index))
        }
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(CommentListContainer)